import os
import PyInstaller.__main__

# 获取桌面路径
desktop = os.path.join(os.path.expanduser("~"), "Desktop")

# 项目根目录 (当前脚本所在目录)
project_root = os.path.dirname(os.path.abspath(__file__))

# 主脚本路径
script_path = os.path.join(project_root, "main.py")

# 自动查找customtkinter路径
import customtkinter
ctk_path = os.path.dirname(customtkinter.__file__)

PyInstaller.__main__.run([
    script_path,
    '--name=PDF工具箱(支持输出分类)',
    '--onefile',
    '--noconsole',
    '--clean',
    '--noconfirm',
    '--hidden-import=PIL._tkinter_finder',
    '--hidden-import=customtkinter',
    '--hidden-import=cffi',
    '--hidden-import=_cffi_backend',
    '--hidden-import=modules.converter_mixin',
    '--hidden-import=modules.splitter_mixin',
    '--hidden-import=modules.img2pdf_mixin',
    '--hidden-import=modules.merge_mixin',
    '--hidden-import=modules.watermark_mixin',
    '--hidden-import=modules.word2pdf_mixin',
    '--hidden-import=modules.excel2pdf_mixin',
    '--hidden-import=modules.ui_mixin',
    f'--add-data={ctk_path};customtkinter/',
    f'--add-data={os.path.join(project_root, "modules")};modules/',
    '--exclude-module=matplotlib',
    '--exclude-module=numpy',
    '--exclude-module=PyQt6',
    '--exclude-module=PyQt5',
    f'--distpath={desktop}'
])